// 设计删除奖项页面
// 关闭VSCode非必要报警
// ignore_for_file: camel_case_types, sized_box_for_whitespace, use_build_context_synchronously, must_be_immutable, non_constant_identifier_names, unused_import                  

import 'package:flutter/material.dart';
import 'package:project_award_statistics/utils/load_award_info_from_db/load_award_info.dart';
import 'package:project_award_statistics/utils/my_yaru_buttons/my_yaru_button_delete.dart';
import 'package:project_award_statistics/utils/my_yaru_buttons/my_yaru_button_normal.dart';
import 'package:provider/provider.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:yaru/yaru.dart';

class Dialog_DeleteAwardInfo extends StatelessWidget {
  //从调用函数中获取删除用户数据的获奖必要信息
  String stu_name;   //获取用户姓名
  String award_name;   //获取奖项名称
  String award_time;   //获取获奖时间
  //这里默认一个奖项一年只能获得一次

  Dialog_DeleteAwardInfo({
    super.key,
    required this.stu_name,
    required this.award_name,
    required this.award_time,
  });

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      backgroundColor: Theme.of(context).colorScheme.surface,
      // 设置对话框标题及布局
      titlePadding: EdgeInsets.all(0),
      title: YaruDialogTitleBar(
        title: Text(
          "删除获奖信息提示",
          style: TextStyle(
            fontSize: 18,
            fontWeight: FontWeight.bold,
          ),
        ),
        isClosable: false,    // 设置不可通过标题右上角关闭,只能通过按对话框进行关闭
      ),
      content: Container(
        height: 110,
        width: 400,
        child: Padding(
          padding: EdgeInsets.only(left:5.0,right:5.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,    // 设置上下两行通过SizedBox间距控制
            children: [
              Text(
                "确认删除此获奖信息吗? 删除后不可恢复!",
                style:TextStyle(
                  fontSize: 20,
                ),
              ),
              const SizedBox(height: 30,),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Container(
                    height: 40,
                    width: 100,
                    child: MyYaruButton_Normal(
                      text: "取消", 
                      onPressed: () => Navigator.of(context).pop(),
                    ),
                  ),
                  Container(
                    height: 40,
                    width: 100,
                    child: MyYaruButton_Delete(
                      text: "确认", 
                      onPressed: () async {
                        await context.read<DBProvider_AwardInfo>().delete_award_info(
                          stu_name, 
                          award_name,
                          award_time,
                        );
                        Navigator.of(context).pop();   //关闭对话框
                      },
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
